/**
 * Package:com.goldcitynet.server.mananger;
 * $Id: MainBusinessManager.java,v 1.2 2009/03/30 11:08:01 yangc Exp $
 * Copyright(c) 2001-2005 www.afteryuan.com
 */
package com.afteryuan.server.handler;

import com.afteryuan.server.command.up.CommandUp;
import com.afteryuan.server.handler.Handler;
import com.afteryuan.server.SpringContextLoader;
import com.afteryuan.server.ConnectSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Date;

/**
 * MainBussinessManager
 * <p/>
 * <p><a href="MainBussinessManager.java.html"><i>View Source</i></a></p>
 *
 * @author <a href="mailto:afteryuan@afteryuan.com">$Author: yangc $</a>
 * @version $Revision: 1.2 $
 */
public class SpringHanlderDispatcher {
    private static Log log = LogFactory.getLog(SpringHanlderDispatcher.class);

    public static void doDispath(ConnectSession ioSession, CommandUp c) {
        long start = new Date().getTime();
        getHandler(c).process(ioSession, c);
        log.debug("income command:" + c);
        long end = new Date().getTime();
        log.info(c.sender + "," + c.handler + "," + end + "," + start + "," + (end - start));
    }

    public static Handler getHandler(CommandUp c) {
        return (Handler) SpringContextLoader.getInstance().getBeanFactory().getBean(c.handler);
    }
}